package leetcode.part2;

import org.junit.Test;

public class S125 {
    public boolean isPalindrome(String s) {
        s = s.toLowerCase();
        StringBuilder builder=new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (Character.isLetter(c)||(c>='0'&&c<='9')){
                builder.append(c);
            }
        }
        s = builder.toString();
        int left=0;
        int right=s.length()-1;
        while (left<right){
            if (s.charAt(left)!=s.charAt(right)){
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
    @Test
    public void test(){
        String s="A man, a plan, a canal: Panama";
        String s1="race a car";
        String s2="0P";
        System.out.println(isPalindrome(s));
        System.out.println(isPalindrome(s1));
        System.out.println(isPalindrome(s2));
    }
}
